package dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import dao.interf.IUserDAO;
import dao.pojo.Authority;
import dao.pojo.User;

public class UserDAO extends BaseDAO<User> implements IUserDAO {
	public List<User> findUserByAuthority(final Authority authority)
	throws RuntimeException {
	Session sess = this.getSessionFactory().openSession();
	String sqlQuery = "SELECT m1.user FROM GroupUser m1, GroupAuthority m2" +
			" WHERE m2.authority = :authority AND m2.group=m1.group";
	Query query = null;
	List<User> lst = new ArrayList<User> (0);
	try {
		query = sess.createQuery(sqlQuery);
		query.setParameter("authority", authority);
		lst = query.list();
	} finally {
		if(null != sess) {
			sess.close();
			sess = null;
		}
	}
	return lst;
	}
}
